package cn.iocoder.yudao.module.product.controller.app.category.vo;

import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

@Data
public class IndexProductVO {

    private Long productSpuId;

    /**
     * 商品名称
     */
    private String name;

    /**
     * 商品简介
     */
    private String introduction;

    private String picUrl;

    /**
     * 商品轮播图
     */
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<String> sliderPicUrls;


    private Long productSkuId;

    private Integer price;

    private Double weight;

    public IndexProductVO(ProductSpuDO productSpuDO, ProductSkuService productSkuService) {
        this.productSpuId = productSpuDO.getId();
        this.name = productSpuDO.getName();
        this.introduction = productSpuDO.getIntroduction();
        this.picUrl = productSpuDO.getPicUrl();
        this.sliderPicUrls = productSpuDO.getSliderPicUrls();
        List<ProductSkuDO> productSkuDOS = productSkuService.getSkuListBySpuId(productSpuDO.getId());
        if (null != productSkuDOS && !productSkuDOS.isEmpty()){
            ProductSkuDO one = productSkuDOS.get(0);
            this.productSkuId = one.getId();
            this.price = one.getPrice();
            this.weight = one.getWeight();
        }
    }
}
